﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    <title>@ViewBag.title 登录界面</title>

    <style>
        body{
            background-color:#eee;
        }
        .loginMiddle {
            height: 370px;
            width: 600px;
            position: absolute;
            text-align: center;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            margin: auto;
        }

        .title {
            width: 100%;
            font: 700 28px/30px "微软雅黑";
            color: #6D6D6D;
            text-align: center;
            margin-top: 50px;
            letter-spacing: 15px;
            margin-bottom: 20px;
        }
    </style>
    <link href="~/lib/bootstrap-3.3.0-dist/dist/css/bootstrap.min.css" rel="stylesheet" />
    <script src="~/lib/jquery/dist/jquery.min.js"></script>
    <script>
        
        var isSafe = @(ViewBag.safeAddress?1:0);
        //获取验证码
        function changeValidateCode() {
            $("#yzmimg").attr("src", "/Account/GetValidateCode" + "?id=" + new Date().getTime());
        }
        $(function () {
            //if (isSafe==1) {
            //    $(".validateDiv").hide();
            //}
            //屏蔽右键菜单
          //  document.oncontextmenu = function () { return false; }
            //更新验证码
            $("#yzmimg").click(function () {
                $("#validateCode").val("");
                changeValidateCode();
            });

            $(".login").click(function () {
                loginPost();
            });
            document.onkeydown = function (e) {
                var ev = document.all ? window.event : e;
                if (ev.keyCode == 13) {
                    loginPost();
                }
            }

        });
        function loginPost() {

            var name = $("#name").val();
            if (name == "") {
                $(".errorDiv").html("请输入登录名");
                return false;
            }
            var password = $("#password").val();
            if (password == "") {
                $(".errorDiv").html("请输入密码");
                return false;
            }
            var validateCode = $("#validateCode").val();
            if (isSafe != 1) {
                if (validateCode == "") {
                    $(".errorDiv").html("请输入验证码");
                    return false;
                }
            }

            $(".login").attr("disabled", "disabled").text("正在登录……");
            $.post("/account/login", { name: name, password: password, validateCode: validateCode }, function (data) {
                if (data.code == 200) {
                    $(".login").text("登录成功正在跳转……");
                    var nodeid = "@ViewBag.nodeid"
                    if (nodeid != "" && nodeid != null && nodeid != undefined) {
                        window.location.href = "/main/index?nodeid=" + nodeid;
                    } else {
                        window.location.href = "/main/index";
                    }
                } else {
                    $(".login").removeAttr("disabled");
                    $(".login").text("登录");
                    $(".errorDiv").html(data.msg);
                }
            });
        }
    </script>
</head>
<body style="text-align:center;vertical-align:central;height:100%;background-color:#eee;">
    <div class="loginMiddle">
        <div class="title">@ViewBag.title</div>
       
        <div>&nbsp;</div>
        <div class="input-group" style="width:300px;margin:auto;">
            <span class="input-group-addon">帐号</span>
            <input type="text" class="form-control" id="name" value="admin" name="name">
        </div>
        <div>&nbsp;</div>
        <div class="input-group" style="width:300px;margin:auto;">
            <span class="input-group-addon">密码</span>
            <input type="password" class="form-control" id="password" value="123456" name="password">
        </div>
        <div>&nbsp;</div>
        <div class="input-group validateDiv" style="width:300px;margin:auto;">
            <span class="input-group-addon">验证码</span>
            <input type="text" class="form-control" id="validateCode" name="validateCode">
            <div style="right:2px;top:2px;bottom:2px; position:absolute;z-index:10">
                <img style="width:100px;height:30px;float:right;cursor:pointer;" title="点击更换验证码" id="yzmimg" src="/Account/GetValidateCode" />
            </div>
        </div>

        <div style="margin-top:20px;">
            <span class="btns btn btn-primary login " style="width:300px;">登录</span>
        </div>
        <div style="margin-top:20px;color:red;" class="errorDiv">
            @ViewBag.error
        </div>
      
    </div>

</body>
</html>
